package com.zwps.biz.controller.http;

import com.zwps.biz.api.model.dto.log.message.BatchDeleteDTO;
import com.zwps.biz.api.model.dto.log.message.SelectLogMessageDTO;
import com.zwps.biz.api.model.vo.log.message.SelectLogMessageVO;
import com.zwps.biz.domain.service.LogMessageService;
import com.zwps.common.api.model.vo.NameCodeOptionVO;
import com.zwps.common.controller.response.message.ResponseDataPageMessage;
import com.zwps.common.core.enums.MessageTypeEnum;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @ClassName: LogMessageController
 * @Description:
 * @author lyh
 * @date 2023年10月19日 下午4:27:23
 *
 */
@Tag(name = "消息日志")
@RestController
@Validated
@RequestMapping("system/log/message")
public class LogMessageController {

    @Autowired
    private LogMessageService logMessageService;

    @Operation(summary = "批量删除")
    @DeleteMapping
    public void deleteLogMessage(@Valid @NotNull @RequestBody BatchDeleteDTO dto) {
        logMessageService.deleteLogMessage(dto.getIds());
    }

    @Operation(summary = "分页查询")
    @GetMapping("page")
    public ResponseDataPageMessage<SelectLogMessageVO> selectLogMessagePage(SelectLogMessageDTO dto) {
        return ResponseDataPageMessage.data(logMessageService.selectLogMessagePage(dto));
    }

    @Operation(summary = "消息类型选项")
    @GetMapping("message_type_option")
    public List<NameCodeOptionVO> selectMessageTypeOption() {
        List<NameCodeOptionVO> list = new ArrayList<NameCodeOptionVO>();
        for (MessageTypeEnum type : MessageTypeEnum.values()) {
            list.add(NameCodeOptionVO.builder().code(type.getCode()).name(type.getName()).build());
        }
        return list;
    }
}
